<template>
  <div><h1>添加电影</h1>
    <p>电影名称：<input type="text" v-model="form.name"></p>
    <p>电影图片：<input type="file" id="pic"></p>
    <p>上映日期：<input type="date" v-model="form.mtime"></p>
    <button @click="add_movie">上传</button>

    <h1>添加演员</h1>
    <p>演员姓名：<input type="text" v-model="yan.name"></p>
    <p>演员年龄：<input type="text" v-model="yan.age"></p>
    <p>演员性别：
      <input type="radio" v-model="yan.sex" value="1" name="1">男
      <input type="radio" v-model="yan.sex" value="2" name="1">女

    </p>
    <p>参演电影：<select name="" id="" v-model="yan.mo">
      <option :value="i.id" v-for="i in movie">{{ i.name }}</option>
    </select>
      <button @click="add_yan">提交</button>

    </p>

    <p><select name="" v-model="form1.mid">
      <option :value="i.id" v-for="i in movie">{{ i.name }}</option>
    </select></p>
    <p><select name="" v-model="form1.yid">
      <option :value="j.id" v-for="j in ayan">{{ j.name }}</option>

    </select></p>
    <button @click="add_sc"></button>

  </div>


</template>

<script>
export default {
  name: "add_my",
  data() {
    return {
      form: {},
      movie: [],
      yan: {},
      ayan: [],
      form1: {}
    }
  },
  methods: {
    add_movie() {
      let formdata = new FormData()
      let pic = document.getElementById('pic').files[0]
      formdata.append('name', this.form.name)
      formdata.append('mtime', this.form.mtime)
      formdata.append('pic', pic)

      this.$axios.post('movie/', formdata)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.form = {}
          } else {
            alert('添加失败')
          }

        })
    },
    get_movie() {
      this.$axios.get('movie/')
        .then(res => {
          this.movie = res.data.list
        })
    },
    get_yan() {
      this.$axios.get('yan/')
        .then(res => {
          this.ayan = res.data.list
        })
    },
    add_yan() {
      this.$axios.post('yan/', this.yan)
        .then(res => {
          if (res.data.code == 200) {
            alert('添加成功')
            this.yan = {}
          } else {
            alert('添加失败')
          }
        })

    },
    add_sc() {
      this.$axios.post('shoucang/', this.form1)
        .then(res => {
          console.log(res.data)

        })
    }
  },
  mounted() {
    this.get_movie()
    this.get_yan()
  }
}
</script>

<style scoped>

</style>
